import 'dart:io';

import 'package:bitcoin_mine/common/global.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

import 'package:chatwoot_sdk/chatwoot_sdk.dart';
import 'package:get/get.dart';
import 'package:get/get_core/src/get_main.dart';

class ChatCustomerPage extends StatefulWidget {
  const ChatCustomerPage({super.key});

  @override
  State<ChatCustomerPage> createState() => _ChatCustomerPageState();
}

class _ChatCustomerPageState extends State<ChatCustomerPage> {
  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return ChatwootWidget(
      websiteToken: "6JFrJeic5ReTCvN7Qy3Wzqfw",
      baseUrl: "http://customer.iuedised.com/",
      user: ChatwootUser(
        identifier:
            "${Global.user.value?.id}#${Global.user.value?.user_info?.id}${Global.platformRefer}",
        name: "${Global.user.value?.id}#${Global.user.value?.user_info?.id}",
        email:
            "${Global.user.value?.id}#${Global.user.value?.user_info?.id}@nine.com",
      ),
      locale: "en",
      closeWidget: () {
        print("close widget");
        if (Platform.isAndroid) {
          SystemNavigator.pop();
        } else if (Platform.isIOS) {
          // exit(0);
          Get.back();
        }
      },
      //attachment only works on android for now
      // onAttachFile: _androidFilePicker,
      onLoadStarted: () {
        print("loading widget");
      },
      onLoadProgress: (int progress) {
        print("loading... $progress");
      },
      onLoadCompleted: () {
        print("widget loaded");
      },
    );
    // return Container();
  }
}
